package web.service.Impl;

import web.bean.Chewei;
import web.bean.XiaoQu;
import web.dao.CheWeiDao;
import web.dao.Impl.CheWeiDaoImpl;
import web.service.CheWeiService;
import web.vo.PageVo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class CheWeiServiceImpl implements CheWeiService {
    CheWeiDao cheWeiDao=new CheWeiDaoImpl();
    @Override
    public PageVo<Chewei> findByInfo(Integer pageSize, Integer pageNo, String startTime, String endTime, String name) {
        Integer params1=(pageNo-1)*pageSize;
        Integer params2=pageSize;
        List<Chewei> info = cheWeiDao.findInfo(params1, params2, startTime, endTime, name);
        int count = cheWeiDao.count(startTime, endTime, name);
        PageVo<Chewei> pageVo=new PageVo<>();
        pageVo.setPageNo(pageNo);
        pageVo.setPageSize(pageSize);
        pageVo.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        pageVo.setCount(count);
        pageVo.setData(info);
        return pageVo;
    }
    public static int number=1;
    @Override
    public int add(Chewei chewei) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String s = sdf.format(date);
        String bianhao="XY"+s;
        if (number<10){
            bianhao=bianhao+"00"+number;
            number++;
        } else if (number<100) {
            bianhao=bianhao+"0"+number;
            number++;
        }else {
            bianhao=bianhao+number;
            number++;
        }
        chewei.setCheweibianhao(bianhao);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        chewei.setAddtime(format);
        return cheWeiDao.add(chewei);
    }

    @Override
    public int del(Integer[] deleteId) {
        return cheWeiDao.del(deleteId);
    }

    @Override
    public Chewei findNameById(Integer id) {
        return cheWeiDao.findNameById(id);
    }

    @Override
    public List<Chewei> findNameAll() {
        return cheWeiDao.findNameAll();
    }

    @Override
    public int editInfo(Chewei chewei) {
        return cheWeiDao.editInfo(chewei);
    }
}
